import { ADD_TODO_ITEM, CHANGE_INPUT_VALUE, INIT_DATA } from './actionTypes'
const defaultState = {
  inputValue: '',
  list: []
};
// reducer 不能修改state
export default (state = defaultState, action) => {
  const newState = JSON.parse(JSON.stringify(state));
  switch (action.type) {
    case CHANGE_INPUT_VALUE:
      newState.inputValue = action.value;
      break;
    case ADD_TODO_ITEM:
      newState.list.push(action.value);
      newState.inputValue = '';
      break;
    case INIT_DATA:
      newState.list = action.value;
      break;
    default:
      break;
  }
  return newState;
}